package com.zscat.mallplus.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zscat.mallplus.active.entity.CmsActive;
import com.zscat.mallplus.annotation.SysLog;
import com.zscat.mallplus.feedback.entity.FeedBack;
import com.zscat.mallplus.service.FeedBackService;
import com.zscat.mallplus.util.StringUtils;
import com.zscat.mallplus.utils.CommonResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author king.wyx@qq.com
 * @date 2020-09-08
 */
@Slf4j
@RestController
@RequestMapping("/api/feedBack")
public class FeedBackController {

    @Autowired
    private FeedBackService feedBackService;

    @SysLog(MODULE = "feedBack", REMARK = "意见反馈列表列表")
    @ApiOperation("意见反馈列表")
    @GetMapping("/list")
    public CommonResult list(String kw,
    						 @ApiParam(name ="pageSiz",value = "页数",defaultValue = "1") Integer pageSiz,
                             @ApiParam(name = "pageNum",value = "条数",defaultValue = "10") Integer pageNum) {
    	QueryWrapper<FeedBack> queryWrapper = new QueryWrapper<>();
        if (Objects.nonNull(kw) && StringUtils.isNotBlank(kw)) {
            kw = "%" + kw.replace(" ", "") + "%";
            queryWrapper.like("content", kw);
        }
    	
        IPage<FeedBack> page = feedBackService.page(
                new Page<>(pageNum, pageSiz),
                queryWrapper.orderByDesc("create_time")
        );
        return new CommonResult().success(page);
    }
}
